package com.mbc.rmt.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

import com.mbc.common.dao.DAO;
import com.mbc.rmt.entities.RemittanceSerial;

public class RemittanceSerialDAOImpls extends DAO<RemittanceSerial> implements RemittanceSerialDAO {

	public RemittanceSerialDAOImpls(Connection conn)
	{
		this.conn = conn;
		this.table_name = "RemittanceSerial";
	}

	@Override
	protected RemittanceSerial readRecord(ResultSet rs) throws SQLException {
		RemittanceSerial l_entity = new RemittanceSerial();
				l_entity.setBranchId(rs.getLong("BranchId"));
		l_entity.setCode(rs.getString("Code"));
		l_entity.setTrDate(rs.getDate("TrDate"));
		l_entity.setSerial(rs.getInt("Serial"));

		return l_entity;
	}

	@Override
	public String getVoucherNo(long branchId, Date trDate, String code)
			throws SQLException {
		query = "exec sp_rmt_serial @param1=?,@param2=?,@param3=?;";
		pstmt = conn.prepareStatement(query);
		pstmt.setLong(1, branchId);
		pstmt.setDate(2, new java.sql.Date(trDate.getTime()));
		pstmt.setString(3, code);
		rs = pstmt.executeQuery();
		rs.next();
		String l_receiptNo = rs.getString(1);
		rs.close();
		pstmt.close();
		return l_receiptNo;
	}
}
